home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet internetowy / Przegladarki internetowe / Mozilla Seamonkey 1.0.5 pl / seamonkey-1.0.5.pl-PL.win32.installer.exe / MAIL.XPI / bin / chrome / messenger.jar / content / messenger / aw-login.js < prev    next >
Encoding:
JavaScript  |  2004-05-24  |  5.6 KB  |  147 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Alec Flett <alecf@netscape.com>
  24.  *   Seth Spitzer <sspitzer@netscape.com>
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  28.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. var protocolinfo = null;
  41. var gPrefsBundle;
  42.  
  43. function loginPageValidate() {
  44.   var username = document.getElementById("username").value;
  45.  
  46.   if (protocolinfo && protocolinfo.requiresUsername && (!username || username == "")) { 
  47.       var alertText = gPrefsBundle.getString("enterUserName");
  48.       window.alert(alertText);
  49.       return false;
  50.   }
  51.  
  52.   var pageData = parent.GetPageData();
  53.   var serverType = parent.getCurrentServerType(pageData);
  54.   var hostName = parent.getCurrentHostname(pageData);
  55.  
  56.   if (parent.AccountExists(username,hostName,serverType)) {
  57.     alertText = gPrefsBundle.getString("accountExists");
  58.     window.alert(alertText);
  59.     return false;
  60.   }
  61.  
  62.   // If SMTP username box is blank it is because the
  63.   // incoming and outgoing server names were the same,
  64.   // so set to be same as incoming username
  65.   var smtpusername = document.getElementById("smtpusername").value || username;
  66.  
  67.   setPageData(pageData, "login", "username", username);
  68.   setPageData(pageData, "login", "smtpusername", smtpusername);
  69.  
  70.   return true;
  71. }
  72.  
  73. function loginPageInit() {
  74.     gPrefsBundle = document.getElementById("bundle_prefs");
  75.     var pageData = parent.GetPageData();
  76.     var loginNameInput = document.getElementById("username");
  77.     
  78.     if (loginNameInput.value == "") {
  79.       // retrieve data from previously entered pages
  80.       var type = parent.getCurrentServerType(pageData);
  81.  
  82.       dump("type = " + type + "\n");
  83.       protocolinfo = Components.classes["@mozilla.org/messenger/protocol/info;1?type=" + type].getService(Components.interfaces.nsIMsgProtocolInfo);
  84.  
  85.       if (protocolinfo.requiresUsername) {
  86.         // since we require a username, use the uid from the email address
  87.         loginNameInput.value = parent.getUsernameFromEmail(pageData.identity.email.value);
  88.       }
  89.     }
  90.  
  91.     var smtpNameInput = document.getElementById("smtpusername");
  92.     var smtpServer = parent.smtpService.defaultServer;
  93.     if (smtpServer && smtpServer.hostname && smtpServer.username &&
  94.         smtpServer.redirectorType == null) {
  95.       // we have a default SMTP server, so modify and show the static text
  96.       // and store the username for the default server in the textbox.
  97.       modifyStaticText(smtpServer.username, "2")
  98.       hideShowLoginSettings(2, 1, 3);
  99.       smtpNameInput.value = smtpServer.username;
  100.     }
  101.     else {
  102.       // no default SMTP server yet, so need to compare
  103.       // incoming and outgoing server names
  104.       var smtpServerName = pageData.server.smtphostname.value;
  105.       var incomingServerName = pageData.server.hostname.value;
  106.       if (smtpServerName == incomingServerName) {
  107.         // incoming and outgoing server names are the same, so show
  108.         // the static text and make sure textbox blank for later tests.
  109.         modifyStaticText(smtpServerName, "3")
  110.         hideShowLoginSettings(3, 1, 2);
  111.         smtpNameInput.value = "";
  112.       }
  113.       else {
  114.         // incoming and outgoing server names are different, so set smtp
  115.         // username's textbox to be the same as incoming's one, unless already set.
  116.         hideShowLoginSettings(1, 2, 3);
  117.         smtpNameInput.value = smtpNameInput.value || loginNameInput.value;
  118.       }
  119.     }
  120. }
  121.  
  122. function hideShowLoginSettings(aEle, bEle, cEle)
  123. {
  124.     document.getElementById("loginSet" + aEle).hidden = false;
  125.     document.getElementById("loginSet" + bEle).hidden = true;
  126.     document.getElementById("loginSet" + cEle).hidden = true;
  127. }
  128.  
  129. var savedPassword="";
  130.  
  131. function onSavePassword(target) {
  132.     dump("savePassword changed! (" + target.checked + ")\n");
  133.     var passwordField = document.getElementById("server.password");
  134.     if (!passwordField) return;
  135.     
  136.     if (target.checked) {
  137.         passwordField.removeAttribute("disabled");
  138.         passwordField.value = savedPassword;
  139.     }
  140.     else {
  141.         passwordField.setAttribute("disabled", "true");
  142.         savedPassword = passwordField.value;
  143.         passwordField.value = "";
  144.     }
  145.     
  146. }
  147.